package ESP.Util;

import java.io.File;

public class RemoveFile {
	
	public static String pathHome = "D:/programFiles/Tomcat7.0/apache-tomcat-7.0.33/webapps/ESP";

	/**
	 * 删除某个文件夹下的所有文件夹和文件
	 */
	public static boolean deletefile(String delpath) {
		try {
			File file = new File(delpath);
			System.out.println(file.getAbsolutePath());
			if (!file.isDirectory()) {
				file.delete();
			} else if (file.isDirectory()) {
				String[] filelist = file.list();
				for (int i = 0; i < filelist.length; i++) {
					File delfile = new File(delpath + "\\" + filelist[i]);
					if (!delfile.isDirectory()) {
						System.out.println("path=" + delfile.getPath());
						System.out.println("absolutepath=" + delfile.getAbsolutePath());
						System.out.println("name=" + delfile.getName());
						delfile.delete();
						System.out.println("删除文件成功");
					} else if (delfile.isDirectory()) {
						deletefile(delpath + "\\" + filelist[i]);
					}
				}
				file.delete();
			}
		} catch (Exception e) {
			System.out.println("deletefile() Exception:" + e.getMessage());
		}
		return true;
	}
}